package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.controller.RoleController;
import com.qk.entity.Dept;
import com.qk.entity.Role;
import com.qk.mapper.RoleMapper;
import com.qk.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public PageResult<Role> selectList(String name, String label, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        List<Role> roles = roleMapper.getSelectList(name, label);

        Page<Role> p = (Page<Role>) roles;
        return new PageResult<>(p.getTotal(), p.getResult());
    }

    @Override
    public void deleteById(Integer id) {
        log.info("删除角色,id={}", id);
        roleMapper.deleteById(id);
    }

    @Override
    public void add(Role role) {
        role.setCreateTime(LocalDateTime.now());
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.insert(role);
    }

    @Override
    public Role selectById(Integer id) {
        log.info("查询角色,id={}", id);
        Role role=roleMapper.SeleceById(id);
        return role;
    }

    @Override
    public void update(Role role) {
        log.info("更新角色");
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.update(role);
    }

    @Override
    public List<Role> allList() {
        List<Role> roleList=roleMapper.allList();
        return roleList;
    }
}
